package com.tz.tzgw.pc.web.dao;

import com.tz.tzgw.pc.web.model.Company;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class CompanyDao {
    private final JdbcTemplate jdbcTemplate;

    public CompanyDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public Company getInfo() {
        String sql = "SELECT * FROM tz_company WHERE id = 1";
        List<Company> result = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Company.class));
        if (result.isEmpty()) {
            return null; // 或者执行其他相应的逻辑
        } else {
            return result.get(0);
        }
    }

    public int updateSite(Company company) {
        String sql = "UPDATE tz_company SET name = ?, address = ?, zipcode = ?, contacts = ?, mobile = ?, phone = ?, fax = ?, email = ?, qnum = ? WHERE id = 1";
        int result = jdbcTemplate.update(sql, company.getName(), company.getAddress(), company.getZipcode(), company.getContacts(), company.getMobile(), company.getPhone(), company.getFax(), company.getEmail(), company.getQnum());
        return result;

    }
}
